package com.weirdor.elasticsearch.plugin;

import com.jfinal.plugin.IPlugin;
import com.weirdor.elasticsearch.kit.ElasticSearchKit;
import org.elasticsearch.client.transport.TransportClient;

import java.util.logging.Logger;

/**
 * Created by weirdor on 2017/12/19.
 * 文件描述:Elasticsearch for JFinal 插件
 */
public class ElasticSearchJFinalPlugin extends ElasticSearchPlugin  implements IPlugin {


    protected final Logger logger = Logger.getLogger(this.getClass().getName());

    private TransportClient client;

    @Override
    public boolean start() {
        client = getTransportClient();
        ElasticSearchKit.INSTANCE.init(client);
        return true;
    }

    @Override
    public boolean stop() {
        if (client != null) {
            logger.info("关闭连接");
            client.close();
        }
        return true;
    }

}
